<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title><?php echo $title;?></title>
<link href="<?php echo base_url(); ?>assets/public/css/reset.css" media="screen" rel="stylesheet" type="text/css" />
<link href="<?php echo base_url(); ?>assets/public/css/style.css" media="screen" rel="stylesheet" type="text/css" />
<!--[if IE]>
<link href="css/ie.css" media="screen" rel="stylesheet" type="text/css">
<![endif]-->
<?php 
foreach($css_files as $file): ?>
	<link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
<?php endforeach; ?>
        <style type="text/css">
            select {
                min-width: 400px;
            }
        </style>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/public/js/jquery-1.4.4.min.js"></script>
<?php foreach($js_files as $file): ?>
<script type="text/javascript" src="<?php echo $file; ?>"></script>
<?php endforeach; ?>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/public/js/jquery-tipsy.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/public/js/jquery-custom.js"></script>
</head>
<body>
<div class="shadow"></div>
<!-- .shadow -->
<?php $this->load->view("common/header_view"); ?>
 <?php $this->load->view("common/sidebar_view",$sb);?>
<!-- BEGIN CONTENT -->
<div id="content">
    <div class="box-out">
    	<div class="box-in">
    		<div class="box-head"><h1><?php echo $content_title;?></h1></div>
                <div class="box-content" id="personnel_content">
                            <!--*********************Layout content********************************-->
                            
                         <div class="form">  
                            <form method="post" id="addform" action="<?php echo base_url() ?>managers/addprocess/<?php echo $pj_id; ?>">
                            <?php if($suc!=null){ ?>
                            <div class="notification success">
                                        <div class="messages"><?php echo $suc;?> <div class="close"><img alt="close" src="<?php echo base_url(); ?>assets/public/img/icon/close.png"></div></div>
                            </div>
                            <?php } ?>
                                <p id="radio_type"><input type="radio" id="radio_option" checked="checked" name="status" value="0"/> Chưa được phép phân công <input type="radio" value="1" name="status" />Được phép phân công</p>
                                <?php if( is_admin() ||  is_pm($pj_id)) { ?>
                                <label>Công việc</label>
                                <?php if(is_array($works_free)) echo fillDropdown('work','text','work', $works_free, 'id','name',null); ?>
                                <br/>
                                <label>Nhân viên</label>
                                <select class="text" name="pn" id="pn">
                                    <?php echo $pns ?>
                                </select>
                                <?php } else { ?>
                                    <label>Công việc</label>
                                    <select id="work" class="text" name="work">
                                        <?php
                                            if(is_array($works_free)) {
                                                echo arrTooptions($works_free,'name','id', true);
                                            }
                                        ?>
                                    </select>
                                    <br/>
                                    <label>Nhân viên</label>
                                    <select class="text" name="pn" id="pn">
                                        
                                    </select>
                                    <script>
                                        $('#work').change(function(){
                                            var work_id = $('#work').val();
                                            var pj_id = <?php echo $pj_id; ?>;
                                            $.ajax({
                                            url: <?php echo "'".  base_url()."managers/ajax_get_pn_of_boss_work/"."'";?>+work_id+'/'+pj_id,
                                            type:'POST',
                                            dataType: 'json',
                                            success: function(output_string){
                                                    $("#pn").find('option').remove().end().append(output_string);
                                                } 
                                            });//End ajax
                                        });
                                    </script>
                                    
                                <?php } ?>
                                <br/>
                                <input type="button" ata-reveal-id="myModal" id="btnadd" class="submit" name="btnadd" value="Lưu lại"/>
                                <script>
                                    $("#btnadd").click(function(e){
                                        var pj_id = <?php echo $pj_id; ?>;
                                        var pn_id = $('#pn').find('option:selected').val();
                                        var work_id = $('#work').find('option:selected').val();
                                        if(work_id==null || pn_id==null){
                                            alert('Chọn nhân viên và công việc !');
                                        }
                                        else {
                                            $.ajax({
                                            url: <?php echo "'".  base_url()."managers/ajax_is_free_with_project_pn/"."'";?>+pj_id+'/'+pn_id,
                                            type:'POST',
                                            success: function(output_string){
                                                   if(output_string=='true'){
                                                      $('#addform').submit();
                                                   }else {
                                                      var url = <?php echo "'".base_url()."managers/check/'"; ?>+pj_id+'/'+pn_id+'/'+work_id;
                                                      $('#img_work').attr('src',url);
                                                      e.preventDefault();
                                                      $('#myModal').reveal();
                                                   }                   
                                                } 
                                            });//End ajax
                                        }
                                        
                                        //$('#addform').submit();
                                    });
                                </script>
                                </form>
                            </div><!--end .form-->
                        </div><!--end .boxcontent--->
                    </div>
                    <!--*********************End layout content****************************-->
                </div>
        </div>
        <div id="myModal" class="reveal-modal">
			<h1>Bảng so sánh công việc</h1>	<br/>		
                        <div style="overflow: scroll">
                            <img src="" id="img_work"/>
                        </div>
                        <p style="margin-top: 10px"><input id="btndoadd" class="mysubmit" type="button" value="Đồng ý thêm" /></p>
                        <script type="text/javascript">
                            $("#btndoadd").click(function(){
                                $('#addform').submit();
                            });
                        </script>
                        <a class="close-reveal-modal">&#215;</a>
	</div>
  
<!--- END CONTENT --->

</body>
</html>
